package homework.day29;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.InputStreamReader;

public class FileCalculator {

	public static void main(String[] args) throws Exception {
		FileCalculator fc = new FileCalculator();
		fc.addCalculateResult("E:\\Test.txt");		
	}
	
	public void addCalculateResult(String inputFileName) throws Exception {
		
		BufferedReader br = null;
		BufferedWriter bw = null;
		
		br = new BufferedReader(new FileReader(inputFileName));
		bw = new BufferedWriter(new FileWriter(inputFileName, true));
		
		int sum = 0;
		int multi = 1;
		while(true){
			int num = br.read();
			
			if(num>47 && num<58){
				num -= 48;
				sum += num;
				multi *= num;
			}
			
			if(num == -1){
				break;
			}
		}
		bw.newLine();
		bw.flush();
		bw.write(sum + "");
		bw.newLine();
		bw.write(multi + "");	
		br.close();
		bw.close();	
	}
}
